#pragma once

#include <map>
#include <utility>
#include "CG_flip_flop.h"


using namespace std;


typedef struct coord
{
	float x;
	float y;
} CG_coord;



class CG_ff_grid
{
		struct loc_comp
		{
			bool operator()(const CG_coord& a, const CG_coord& b)
			{
				if(a.y + CG_flip_flop::get_radius() < b.y)
				{
					return true;
				}
				if(a.y + CG_flip_flop::get_radius() > b.y)
				{
					return false;
				}
				return (a.x + CG_flip_flop::get_radius() < b.x);
			}
		};
		typedef map<const CG_coord, CG_flip_flop, loc_comp> ff_map_type;
		typedef ff_map_type::iterator ff_map_iter;
		ff_map_type myGrid; 
	public:
		CG_ff_grid(short square) { CG_flip_flop::set_radius(square); }
		~CG_ff_grid();
		bool CG_ff_grid_insert(CG_flip_flop *ff);
		long CG_ff_grid_get_size();
		CG_flip_flop *CG_ff_grid_get_element_by_id(long anID);
		CG_flip_flop *CG_ff_grid_get_first();
		CG_flip_flop *CG_ff_grid_get_next(CG_flip_flop *ff);
};
